import { http, ResultList } from "@/utils/http";

// 分页查询字项
export const getDictPage = (data: DictVO) => {
	return http.request<defResult>("post", `/dict/item/page`, { data });
}
// 新增字典项
export const addDictItem = (data: DictItemVO) => {
	return http.request<defResult>("post", "/dict/item", { data });
}
// 修改字典项
export const updateDictItem = (data: DictItemVO) => {
	return http.request<defResult>("put", "/dict/item", { data });
}
// 删除字典项
export const deleteDictItem = (id: string) => {
	return http.request<defResult>("delete", `/dict/item/${id}`);
}
// 批量删除字典项
export const deleteDictItemBatch = (data: string[]) => {
	return http.request<defResult>("delete", `/dict/item/batch`, { data });
}
// 刷新字典缓存
export const refreshCache = () => {
	return http.request<defResult>("delete", `/dict/refresh`);
}
// 根据字典类型ID查询字典项列表
export const getDictItemList = (dictTypeId: string) => {
	return http.request<DictItemResultVO>("get", `/dict/item/type/${dictTypeId}`);
}
// 根据ID获取字典项
export const getDictItemById = (id: string) => {
	return http.request<DictItemResultVO>("get", `/dict/item/${id}`);
}
// 新增字典类型
export const addDictType = (data: DictVO) => {
	return http.request<defResult>("post", "/dict/type", { data });
}
// 修改字典类型
export const updateDictType = (data: DictVO) => {
	return http.request<defResult>("put", "/dict/type", { data });
}
// 删除字典类型
export const deleteDictType = (id: string) => {
	return http.request<defResult>("delete", `/dict/type/${id}`);
}
// 批量删除字典类型
export const deleteDictTypeBatch = (data: string[]) => {
	return http.request<defResult>("delete", `/dict/type/batch`, { data });
}
// 分页查询字典类型
export const getDictTypePage = (data: object) => {
	return http.request<defResult>("post", `/dict/type/page`, { data });
}
// 根据ID获取字典类型
export const getDictTypeById = (id: string) => {
	return http.request<defResult>("get", `/dict/type/${id}`);
}
// 根据编码获取字典类型
export const getDictTypeByCode = (code: string) => {
	return http.request<defResult>("get", `/dict/type/code/${code}`);
}
// 根据字典类型编码查询字典项列表/dict//{}
export const getDictItemListByCode = (dictTypeCode: string) => {
	return http.request<ResultList>("get", `/dict/data/${dictTypeCode}`);
}
// 根据字典类型编码获取键值Map
export const getDictItemMapByCode = (dictTypeCode: string) => {
	return http.request<ResultList>("get", `/dict/map/${dictTypeCode}`);
}

export type defResult = {
	/**
		 * 状态码
		 */
	code?: number;
	/**
	 * 返回数据
	 */
	data?: PageInfoDictTypeVO;
	/**
	 * 返回信息
	 */
	message?: string;
	[property: string]: any;
}
/**
 * 返回数据
 *
 * PageInfoDictTypeVO
 */
export type PageInfoDictTypeVO = {
	endRow?: number;
	hasNextPage?: boolean;
	hasPreviousPage?: boolean;
	isFirstPage?: boolean;
	isLastPage?: boolean;
	list?: DictVO[];
	navigateFirstPage?: number;
	navigateLastPage?: number;
	navigatepageNums?: number[];
	navigatePages?: number;
	nextPage?: number;
	pageNum?: number;
	pages?: number;
	pageSize?: number;
	prePage?: number;
	size?: number;
	startRow?: number;
	total?: number;
	[property: string]: any;
}
/**
 * 字典类型DTO
 *
 * DictTypeDTO
 */
export type DictVO = {
	/**
	 * 字典编码
	 */
	code: string;
	/**
	 * 主键ID（创建时不需要，更新时必须）
	 */
	id?: string;
	/**
	 * 字典名称
	 */
	name: string;
	/**
	 * 备注
	 */
	remark?: string;
	/**
	 * 状态（0-禁用，1-正常）
	 */
	status?: number;
	[property: string]: any;
}
/**
 * 字典项
 *
 * ResultDictItemVO
 */
export type DictItemResultVO = {
	/**
	 * 状态码
	 */
	code?: number;
	/**
	 * 返回数据
	 */
	data?: DictItemVO;
	/**
	 * 返回信息
	 */
	message?: string;
	[property: string]: any;
}

/**
 * 返回数据
 *
 * DictItemVO
 */
export type DictItemVO = {
	/**
	 * 创建人
	 */
	createBy?: string;
	/**
	 * 创建时间
	 */
	createTime?: string;
	/**
	 * 样式属性（其他样式扩展）
	 */
	cssClass?: string;
	/**
	 * 字典类型编码
	 */
	dictTypeCode?: string;
	/**
	 * 字典类型ID
	 */
	dictTypeId?: string;
	/**
	 * 主键ID（UUID）
	 */
	id?: string;
	/**
	 * 是否默认（0-否，1-是）
	 */
	isDefault?: number;
	/**
	 * 字典标签
	 */
	label?: string;
	/**
	 * 表格回显样式
	 */
	listClass?: string;
	/**
	 * 备注
	 */
	remark?: string;
	/**
	 * 排序号
	 */
	sort?: number;
	/**
	 * 状态（0-禁用，1-正常）
	 */
	status?: number;
	/**
	 * 更新人
	 */
	updateBy?: string;
	/**
	 * 更新时间
	 */
	updateTime?: string;
	/**
	 * 字典值
	 */
	value?: string;
	[property: string]: any;
}